package com.san.oms.factory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.san.common.utils.Constant;
import com.san.metadata.domain.DataSourceDO;
import com.san.metadata.service.DataSourceService;
import com.san.oms.dao.ScoreManager;
import com.san.oms.dao.score.ScoreMysqlManager;
import com.san.oms.dao.score.ScoreOracleManager;

/**
 * 模型评分计算JDBC访问层工厂类
 * 
 * @author xiangyz
 *
 */
@Service
public class ScoreManagerFactory {
	@Autowired
	ScoreOracleManager scoreOracleManager;

	@Autowired
	ScoreMysqlManager scoreMysqlManager;
	
	@Autowired
	DataSourceService dataSourceService;

//	private ScoreManagerFactory() {
//	};
//
//	public static ScoreManagerFactory getInstance() {
//		return Singleton.INSTANCE.getInstance();
//	}
//
//	private static enum Singleton {
//		INSTANCE;
//
//		private ScoreManagerFactory singleton;
//
//		// JVM会保证此方法绝对只调用一次
//		private Singleton() {
//			singleton = new ScoreManagerFactory();
//		}
//
//		public ScoreManagerFactory getInstance() {
//			return singleton;
//		}
//	}

	/**
	 * 获取
	 * 
	 * @param modelType
	 */
	public ScoreManager getManager() {
		DataSourceDO dataSourceDO = null;
		try {
			dataSourceDO = dataSourceService.getByCode(Constant.SOURCE_CODE_BASESOURCE);
		} catch (Exception e) {
			e.printStackTrace();
		}
		ScoreManager scoreManager = null;
		switch (dataSourceDO.getSourceType()) {
		case Constant.SOURCE_TYPE_ORACLE:
			scoreManager = scoreOracleManager;
			break;
		case Constant.SOURCE_TYPE_MYSQL:
			scoreManager = scoreMysqlManager;
			break;
		default:
			break;
		}

		return scoreManager;
	}

}
